/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jifPlantillaInventario.java
 *
 * Created on 17-sep-2010, 13:25:53
 */

package Inventario;

import administracion.helper.Listas;
import administracion.helper.Reportes;
import administracion.helper.Utiles_MensajesDialogo;
import Ordenes.jifRegistrarOrdenCompra;
import java.awt.event.KeyEvent;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import suministros.ejb30.TO.AlmacenTO;
import suministros.ejb30.TO.SubAlmacenTO;
import suministros.ejb30.TO.ZonaTO;

/**
 *
 * @author Luis_Angel
 */
public class jifPlantillaInventario extends javax.swing.JInternalFrame {

    /** Creates new form jifPlantillaInventario */
    public jifPlantillaInventario() {
        
        initComponents();
        llenarComboZona();
    }

     private void llenarComboZona() {
            List listaZonas = null;
            List listaZonas_cbo = this.cboBeanBindingZona1.getLista();
            listaZonas_cbo.clear();
            try
            {
              listaZonas = Listas.getZonas();
              this.cboBeanBindingZona1.setLista(listaZonas);
              this.bindingGroup.bind();
              this.jcboZona.updateUI();
              this.jcboZona.setSelectedIndex(0);
            } catch (Exception ex) {
              Utiles_MensajesDialogo.mensajeAlerta("Error al obtener zonas\n" + ex.getMessage());
              ex.printStackTrace();
              Logger.getLogger(jifRegistrarOrdenCompra .class.getName()).log(Level.SEVERE, null, ex);
            }
     }

      private void llenarComboAlmacen() {
           try {
                  if (this.jcboZona.getSelectedItem() != null) {
                    ZonaTO selected = (ZonaTO)this.jcboZona.getSelectedItem();
                    List listaAlmacen = null;
                    List listaAlmacen_cbo = this.cboBeanBindingAlmacen1.getLista();
                    listaAlmacen_cbo.clear();
                    listaAlmacen = Listas.getAlmacenEnZona(selected);
                    this.cboBeanBindingAlmacen1.setLista(listaAlmacen);
//                    this.bindingGroup.bind();
                    this.jcboAlmacen.updateUI();
                    this.jcboAlmacen.setSelectedIndex(0);
                  }
          }
            catch (Exception e) {
              Utiles_MensajesDialogo.mensajeAlerta("Error al obtener almacenes\n" + e.getMessage());
              e.printStackTrace();
              Logger.getLogger(jifRegistrarOrdenCompra.class.getName()).log(Level.SEVERE, null, e);
            }
     }
      
      private void llenarComboUbicacion() {
       try {
                  if (this.jcboAlmacen.getSelectedItem() != null) {
                    AlmacenTO selected = (AlmacenTO)this.jcboAlmacen.getSelectedItem();
                    List listaSubAlmacen = null;
                    List listaSubAlmacen_cbo = this.cboBeanBindingSubAlmacen1.getLista();
                    listaSubAlmacen_cbo.clear();
                    listaSubAlmacen = Listas.getSubAlmacenEnAlmacen(selected);
                    this.cboBeanBindingSubAlmacen1.setLista(listaSubAlmacen);
                 //   this.bindingGroup.bind();
                    this.jcboUbicacion.updateUI();
                    this.jcboUbicacion.setSelectedIndex(0);
                  }
          }
            catch (Exception e) {
              Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Sub Almacenes\n" + e.getMessage());
              e.printStackTrace();
              Logger.getLogger(jifRegistrarOrdenCompra.class.getName()).log(Level.SEVERE, null, e);
            }
     }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cboBeanBindingSubAlmacen1 = new administracion.BeanBinding.CboBeanBindingSubAlmacen();
        cboBeanBindingZona1 = new administracion.BeanBinding.CboBeanBindingZona();
        cboBeanBindingAlmacen1 = new administracion.BeanBinding.cboBeanBindingAlmacen();
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jcboAlmacen = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jcboZona = new javax.swing.JComboBox();
        jcboUbicacion = new javax.swing.JComboBox();
        jbSalir = new javax.swing.JButton();

        setIconifiable(true);
        setTitle("GENERAR PLANILLA INVENTARIO");

        jButton1.setFont(new java.awt.Font("Arial", 1, 12));
        jButton1.setText("GENERAR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DETALLES DEL REPORTE", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 255))); // NOI18N

        jcboAlmacen.setFont(new java.awt.Font("Arial", 0, 12));
        jcboAlmacen.setToolTipText("Zona a la que se cargara el pedido"); // NOI18N

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingAlmacen1, eLProperty, jcboAlmacen);
        bindingGroup.addBinding(jComboBoxBinding);

        jcboAlmacen.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcboAlmacenItemStateChanged(evt);
            }
        });
        jcboAlmacen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboAlmacenActionPerformed(evt);
            }
        });
        jcboAlmacen.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboAlmacenKeyPressed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel5.setText("ALMACEN"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel2.setText("SUCURSAL"); // NOI18N

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel6.setText("UBICACION"); // NOI18N

        jcboZona.setFont(new java.awt.Font("Arial", 0, 12));
        jcboZona.setToolTipText("Almacen al que se cargara La Orden"); // NOI18N

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingZona1, eLProperty, jcboZona);
        bindingGroup.addBinding(jComboBoxBinding);

        jcboZona.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcboZonaItemStateChanged(evt);
            }
        });
        jcboZona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboZonaActionPerformed(evt);
            }
        });
        jcboZona.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboZonaKeyPressed(evt);
            }
        });

        jcboUbicacion.setFont(new java.awt.Font("Arial", 0, 12));
        jcboUbicacion.setToolTipText("Ubicaciones dentero de un Almacen"); // NOI18N

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingSubAlmacen1, eLProperty, jcboUbicacion);
        bindingGroup.addBinding(jComboBoxBinding);

        jcboUbicacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboUbicacionActionPerformed(evt);
            }
        });
        jcboUbicacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboUbicacionKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2)
                        .addComponent(jLabel5)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jcboUbicacion, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jcboAlmacen, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jcboZona, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jcboZona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcboAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(5, 5, 5)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcboUbicacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jbSalir.setFont(new java.awt.Font("Arial", 1, 12));
        jbSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jbSalir.setMnemonic('C');
        jbSalir.setText("CERRAR");
        jbSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbSalir))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jbSalir});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jbSalir))
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jcboAlmacenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcboAlmacenItemStateChanged

    }//GEN-LAST:event_jcboAlmacenItemStateChanged

    private void jcboAlmacenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboAlmacenActionPerformed
         if(this.jcboAlmacen.getSelectedIndex()>=0)
                this.llenarComboUbicacion();
}//GEN-LAST:event_jcboAlmacenActionPerformed

    private void jcboAlmacenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboAlmacenKeyPressed

        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jcboAlmacen.requestFocus();
        }
}//GEN-LAST:event_jcboAlmacenKeyPressed

    private void jcboZonaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcboZonaItemStateChanged

}//GEN-LAST:event_jcboZonaItemStateChanged

    private void jcboZonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboZonaActionPerformed

        if(this.jcboZona.getSelectedIndex()>=0)
         this.llenarComboAlmacen();

}//GEN-LAST:event_jcboZonaActionPerformed

    private void jcboZonaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboZonaKeyPressed

        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jcboAlmacen.requestFocus();
        }
}//GEN-LAST:event_jcboZonaKeyPressed

    private void jcboUbicacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboUbicacionActionPerformed

}//GEN-LAST:event_jcboUbicacionActionPerformed

    private void jcboUbicacionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboUbicacionKeyPressed

       
}//GEN-LAST:event_jcboUbicacionKeyPressed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Reportes.verPlantillaInventario(Integer.parseInt(((SubAlmacenTO)jcboUbicacion.getSelectedItem()).getCodSubAlmacen()));
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jbSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalirActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            this.dispose();
        }
}//GEN-LAST:event_jbSalirActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private administracion.BeanBinding.cboBeanBindingAlmacen cboBeanBindingAlmacen1;
    private administracion.BeanBinding.CboBeanBindingSubAlmacen cboBeanBindingSubAlmacen1;
    private administracion.BeanBinding.CboBeanBindingZona cboBeanBindingZona1;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jbSalir;
    private javax.swing.JComboBox jcboAlmacen;
    private javax.swing.JComboBox jcboUbicacion;
    private javax.swing.JComboBox jcboZona;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
